<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>汽车衡称重系统</title>
	<link href="__STATIC__/css/common.css" rel="stylesheet">
	<link rel="stylesheet" href="__STATIC__/css/index.css">
	<link rel="stylesheet" type="text/css" href="__STATIC__/js/datetimepicker/jquery.datetimepicker.css"/>
	<style>
		.ms-controller{
			display:none;
		}
	</style>
	<script src="__STATIC__/js/LodopFuncs.js"></script>
	<object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0> 
	  <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
	</object>
</head>
<body ms-controller="view" class="ms-controller" ms-visible="display_main">
	<div class="header" style="display:none;">
		<div class="header-box">
			<ul class="menu-box">
				<li class="menu-item" ms-class="menu-active:menu_label == 'scale'" ms-click="changeMenu('scale')">称重</li>
				<li class="menu-item" ms-class="menu-active:menu_label == 'system'" ms-click="changeMenu('system')">系统维护</li>
				<li class="menu-item" ms-class="menu-active:menu_label == 'report'" ms-click="changeMenu('report')">统计报表</li>
				<li class="menu-item" ms-class="menu-active:menu_label == 'function'" ms-click="changeMenu('function')">财务核算</li>
				<li class="menu-item"><a style="color:blue;" target="_blank" href="/home/index/insertByHand">手动补单</a></li>
			</ul>
		</div>
	</div>

	<div class="main">
		<div class="main-report">
			<select style="width:400px;height:30px;margin-top:10px;text-align:center;margin-bottom:10px;display:none;" ms-change="selectReport" ms-duplex="report_model">
				<option style="width:100%;text-align:center;" value="normalReport">普通报表</option>
				<option style="width:100%;text-align:center;" value="countReport">统计报表</option>
			</select>
			<div class="report-box" ms-visible="report_model == 'normalReport'">
				<div style="width:99%;margin:0 auto;height:30px;padding-top:10px;padding-bottom:10px;border:1px solid #dedede;margin-bottom:10px;" ms-visible="config.timeAreareport == 0">
					<label class="function_input" style="margin-left:5px;">磅房：
						<select  class="function_input" style="width:90px;height:30px;" ms-change="getNormalReport" ms-duplex="normal_search.houseId">
							<option value="">不限</option>
							<option ms-repeat-el="house_list" ms-attr-value="el.houseId">(|el.houseName|)</option>
						</select>
					</label>					
					<label class="function_input" style="margin-left:5px;">日期：
						<input type="text" id="datetimepicker_dark" class="function_input" style="width:110px;" ms-change="getNormalReport" ms-duplex="normal_search.billDate">
					</label>
					<label class="function_input" style="margin-left:5px;">物资名称：
						<select  class="function_input" style="width:70px;height:30px;" ms-change="getNormalReport" ms-duplex="normal_search.goodsName">
							<option value="">不限</option>
							<option ms-repeat-el="goods_list" ms-attr-value="el.goodsName">(|el.goodsName|)</option>
						</select>
					</label>
					<label class="function_input" style="margin-left:5px;">发货单位：
						<select  class="function_input" style="width:100px;height:30px;" ms-change="getNormalReport" ms-duplex="normal_search.sendUnit">
							<option value="">不限</option>
							<option ms-repeat-el="customer_receive_list" ms-attr-value="el.customerName">(|el.customerName|)</option>
						</select>
					</label>
					<label class="function_input" style="margin-left:5px;">收货单位：
						<select  class="function_input" style="width:100px;height:30px;" ms-change="getNormalReport" ms-duplex="normal_search.receiveUnit">
							<option value="">不限</option>
							<option ms-repeat-el="customer_receive_list" ms-attr-value="el.customerName">(|el.customerName|)</option>
						</select>
					</label>
					<label class="function_input" style="margin-left:5px;">操作员：
						<select  class="function_input" style="width:70px;height:30px;" ms-change="getNormalReport" ms-duplex="normal_search.fullOperator">
							<option value="">不限</option>
							<option ms-repeat-el="user_list" ms-attr-value="el.userName">(|el.userName|)</option>
						</select>
					</label>
					<button style="width:60px;height:30px;line-height:30px;background-color:#44B549;color:white;border-radius:4px;" ms-click="getNormalReport">刷新</button>
					<button style="width:60px;height:30px;line-height:30px;background-color:#44B549;color:white;border-radius:4px;margin-left:5px;" ms-click="printDailyReport('table')">打印</button>
					<button style="width:60px;height:30px;line-height:30px;background-color:#44B549;color:white;border-radius:4px;margin-left:5px;" ms-click="exportNormalReport()">导出</button>
				</div>
				<div style="width:99%;margin:0 auto;height:30px;padding-top:10px;padding-bottom:10px;border:1px solid #dedede;margin-bottom:10px;" ms-visible="config.timeAreareport == 1">
					<label class="function_input" style="margin-left:3px;">磅房：
						<select  class="function_input" style="width:90px;height:30px;" ms-change="getNormalReport" ms-duplex="normal_search.houseId">
							<option value="">不限</option>
							<option ms-repeat-el="house_list" ms-attr-value="el.houseId">(|el.houseName|)</option>
						</select>
					</label>					
					<label class="function_input" style="margin-left:3px;">开始日期：
						<input type="text" id="datetimepicker_dark_1" class="function_input" style="width:110px;" ms-change="getNormalReport" ms-duplex="normal_search.billDateStart">
					</label>
					<label class="function_input" style="margin-left:3px;">结束日期：
						<input type="text" id="datetimepicker_dark_2" class="function_input" style="width:110px;" ms-change="getNormalReport" ms-duplex="normal_search.billDateEnd">
					</label>
					<label class="function_input" style="margin-left:3px;">物资名称：
						<select  class="function_input" style="width:70px;height:30px;" ms-change="getNormalReport" ms-duplex="normal_search.goodsName">
							<option value="">不限</option>
							<option ms-repeat-el="goods_list" ms-attr-value="el.goodsName">(|el.goodsName|)</option>
						</select>
					</label>
					<label class="function_input" style="margin-left:3px;">发货单位：
						<select  class="function_input" style="width:100px;height:30px;" ms-change="getNormalReport" ms-duplex="normal_search.sendUnit">
							<option value="">不限</option>
							<option ms-repeat-el="customer_receive_list" ms-attr-value="el.customerName">(|el.customerName|)</option>
						</select>
					</label>
					<label class="function_input" style="margin-left:3px;">收货单位：
						<select  class="function_input" style="width:100px;height:30px;" ms-change="getNormalReport" ms-duplex="normal_search.receiveUnit">
							<option value="">不限</option>
							<option ms-repeat-el="customer_receive_list" ms-attr-value="el.customerName">(|el.customerName|)</option>
						</select>
					</label>
					<label class="function_input" style="margin-left:3px;">操作员：
						<select  class="function_input" style="width:70px;height:30px;" ms-change="getNormalReport" ms-duplex="normal_search.fullOperator">
							<option value="">不限</option>
							<option ms-repeat-el="user_list" ms-attr-value="el.userName">(|el.userName|)</option>
						</select>
					</label>
					<!-- <button style="width:60px;height:30px;line-height:30px;background-color:#44B549;color:white;border-radius:4px;" ms-click="getNormalReport">刷新</button> -->
					<button style="width:60px;height:30px;line-height:30px;background-color:#44B549;color:white;border-radius:4px;" ms-click="printDailyReport('table')">打印</button>
					<button style="width:60px;height:30px;line-height:30px;background-color:#44B549;color:white;border-radius:4px;margin-left:5px;" ms-click="exportNormalReport()">导出</button>
				</div>
				<div class="report_list_box" id="table">
					<p style="margin-top:20px;text-align:center;font-size:16px;color:red;" ms-visible="normal_report_list.length <= 0">没有查到任何记录</p>
					<table class="report_list" border="1" cellspacing="0" ms-visible="normal_report_list.length > 0" style="margin:0 auto;font-size:14px;table-layout:fixed;border-collapse:collapse;">
						<thead>
						<tr>
							<td colspan="20" style="border:0px !important;height:0px;">
								<h3 style="font-size:20px;text-align:center;margin-top:-25px;" ms-text="config.company + houseName + '过磅单日报表'"></h3>
							</td>
						</tr>
						<tr>
							<td colspan="20" style="border:0px;" align="center">
								当前是第<font tdata="PageNo">##</font>页&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;共<font tdata="PageCount">##</font>页
							</td>
						</tr>
						<tr>
							<th>编号</th>
							<th>磅单编号</th>
							<th>过磅日期</th>
							<th>物资名称</th>
							<th>车牌号码</th>
							<th>司机姓名</th>
							<th>皮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重</th>
							<th>检皮时间</th>
							<th>检皮人员</th>
							<th>毛&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重</th>
							<th>检重时间</th>
							<th>检重人员</th>
							<th>净&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重</th>
							<th>发货单位</th>
							<th>收货单位</th>
							<th>发货位置</th>
							<th>发运路线</th>
							<th>钩机号</th>
							<th>磅房名称</th>							
							<th>打印次数</th>
						</tr>
						</thead>
						<tbody>					
						<tr ms-repeat-el="normal_report_list" ms-class="(|el.bg|)">
							<td ms-text="$index + 1"></td>
							<td ms-text="el.billCode"></td>
							<td ms-text="el.billDateDesc"></td>
							<td ms-text="el.goodsName"></td>
							<td ms-text="el.truckCode"></td>
							<td ms-text="el.driver"></td>
							<td ms-text="el.emptyWeigh"></td>
							<td ms-text="el.emptyTimeDesc"></td>
							<td ms-text="el.emptyOperator"></td>
							<td ms-text="el.fullWeigh"></td>
							<td ms-text="el.fullTimeDesc"></td>
							<td ms-text="el.fullOperator"></td>
							<td ms-text="el.weigh"></td>
							<td ms-text="el.sendUnit"></td>
							<td ms-text="el.receiveUnit"></td>
							<td ms-text="el.position"></td>
							<td ms-text="el.route"></td>
							<td ms-text="el.excavator"></td>
							<td ms-text="el.houseName"></td>							
							<td ms-text="el.printCount"></td>
						</tr>
						
						<tr>
							<td colspan="20">
								<p style="display:inline-block;width:60%;height:40px;line-height:40px;font-size:20px;"></p>
								<p style="display:inline-block;width:15%;text-align:center;height:40px;line-height:40px;font-size:20px;"ms-text="'共' + normal_report_cs + '车'"></p>
								<p style="display:inline-block;width:15%;text-align:center;height:40px;line-height:40px;font-size:20px;" ms-text="'共' + normal_report_sum + '吨'"></p>
							</td>
						</tr>
						</tbody>
					</table>
					
				</div>
			</div>
			<div class="report-box">
			</div>
		</div>
	</div>
	<script src="__STATIC__/js/jquery.min.js"></script>	
	<script src="__STATIC__/js/datetimepicker/build/jquery.datetimepicker.full.js"></script>
	<script src="__STATIC__/js/layer/layer.js"></script>
	<script src="__STATIC__/js/avalon.js"></script>
	<script src="__STATIC__/js/common.js"></script>
	<script src="__STATIC__/js/jquery.cookie.min.js"></script>
	<script src="__STATIC__/js/logic.js"></script>
	<script src="__STATIC__/js/validator.js"></script>
	<script src="__STATIC__/js/video/codebase/webVideoCtrl.js"></script>
	<script src="__STATIC__/js/print.js"></script>

	<script>
	jQuery(document).ready(function(){
		avalon.config({
          interpolate : ["(|","|)"]
        });
        $("#weigh_list").bind("contextmenu", function(){return false;});
        $("#rightMenu").bind("contextmenu", function(){return false;});
		var Tcom = null;
		var w = $(document).width();
		var h = $(document).height();
		

		$.datetimepicker.setLocale('ch');
		$('#datetimepicker_dark').datetimepicker(
			{
				/*theme:'dark',*/
				timepicker:false,
				format:'Y-m-d',
				formatDate:'Y-m-d',
				defaultTime:'00:00',
				defaultDate:new Date().Format('yyyy-MM-dd'),
				/*onSelectDate:function(){
					vm.normal_search.billDate = $("#datetimepicker_dark").val();
					vm.getNormalReport();
				}*/
				onClose:function(){
					var td = $("#datetimepicker_dark").val();
					if(td != vm.normal_search.billDate){
						vm.normal_search.billDate = td;
						vm.getNormalReport();
					}
				}
			}
		);
		$('#datetimepicker_dark_1').datetimepicker(
			{
				/*theme:'dark',*/
				timepicker:true,
				format:'Y-m-d H:i',
				formatDate:'Y-m-d H:i',
				defaultTime:'00:00',
				defaultDate:new Date().Format('yyyy-MM-dd H:i'),
				onClose:function(){
					var td = $("#datetimepicker_dark_1").val();
					if(td != vm.normal_search.billDateStart){
						vm.normal_search.billDateStart = td;
						vm.getNormalReport();
					}
				}
			}
		);
		$('#datetimepicker_dark_2').datetimepicker(
			{
				/*theme:'dark',*/
				timepicker:true,
				format:'Y-m-d H:i',
				formatDate:'Y-m-d H:i',
				defaultTime:'00:00',
				defaultDate:new Date().Format('yyyy-MM-dd H:i'),
				onClose:function(){
					var td = $("#datetimepicker_dark_2").val();
					if(td != vm.normal_search.billDateEnd){
						vm.normal_search.billDateEnd = td;
						vm.getNormalReport();
					}
				}
			}
		);
		$("#weigh_search_date").datetimepicker(
			{
				/*theme:'dark',*/
				timepicker:false,
				format:'Y-m-d',
				formatDate:'Y-m-d',
				defaultTime:'00:00',
				defaultDate:new Date().Format('yyyy-MM-dd'),
				/*onSelectDate:function(){
					vm.weigh_search.date = $("#weigh_search_date").val();
				}*/
				onClose:function(){
					var td = $("#weigh_search_date").val();
					if(td != vm.weigh_search.date){
						vm.weigh_search.date = td;
					}
				}
			}
		);


		var vm = avalon.define({
        	$id : "view",
        	houseId:0,
        	houseName:'',
        	menu_label:'report',
        	user_info:{},
        	user_list:[],
        	user_power:[],
        	weigh_list:[],
        	truck_code_list:[],
        	truck_type_list:[],
        	excavator_list:[],
        	customer_list:[],
        	house_list:[],
        	truck_list:[],
        	config_list:[],
        	route_list:[],
        	position_list:[],
        	position_select:[],
        	position_edit_select:[],
        	customer_receive_list:[],
        	goods_list:[],
        	config:{weighModel:0,codeType:0,codeLen:3,codePagearea:'',codePrintarea:''},
        	weightype:0,
        	codetype:1,
        	report_model:'normalReport',
        	normal_report_list:[],
        	count_report_list:[],
        	normal_search:{billDate:new Date().Format('yyyy-MM-dd'),goodsName:'',sendUnit:'',receiveUnit:'',fullOperator:'',houseId:'',timeArea:0,billDateStart:new Date().Format('yyyy-MM-dd h:m'),billDateEnd:new Date().Format('yyyy-MM-dd h:m')},
        	count_search:{},
        	count_reprort_item:{},
        	normal_report_sum:'',/*显示普通报表总吨数*/
        	normal_report_cs:'',/*显示普通报表总车数*/
        	display_main:true,
        	load:function(){
        		$.post(logic_urls.index,{},
        			function(data,textStatus){
        				var json = TX.toJson(data);
        				console.log(json.data);
        				var t = Date.parse(new Date()) / 1000;
        				if(Math.abs(t - json.time) >= 3000){
        					var tt = new Date(parseInt(json.time) * 1000).toLocaleString();
        					alert('当前系统与服务器时间不同步,服务器时间为:' + tt + ".请手动修改系统时间",{icon:3,skin: 'layer-ext-moon'});
        					vm.display_main = false;
        					return;
        				}
        				for(var k in json.data){
        					vm[k] = json.data[k];
        				}
        				vm.user_power = vm.user_info.power.split(',');
        				if(vm.normal_search.houseId == ''){
	        				vm.normal_search.houseId = vm.houseId;
	        			}
	        			if(vm.normal_search.fullOperator == ''){
	        				vm.normal_search.fullOperator = vm.user_info.userName;
	        			}
	        			vm.getNormalReport();
        				avalon.scan();
        			}
        		);
        	},
        	changeMenu:function(m){
        		if(m == 'system'){
        			/*if(vm.user_info.isManager < 1){
        				TX.msg('您没有权限访问此页',{time:3000});
        				return;
        			}*/
        			window.location.href = '/home/index/system';
        			return;
        		}
        		if(m == 'function'){
        			for(var i=0;i<vm.user_power.length;i++){
        				if(vm.user_power[i] == 'accounting'){
        					window.location.href = '/home/index/accounting';
        					break;
        					return;
        				}
        			}
        			TX.msg('您没有权限访问此页',{time:3000});
        			return;
        		}
        		vm.menu_label = m;
        		if(m == 'scale'){
        			window.location.href = '/home/index/index';
        		}
        	},
        	printDailyReport:function(id){
        		if(vm.normal_report_list.length <=0){
        			TX.msg('没有可以打印的内容',{time:3000});
        			return false;
        		}
        		reportPrint(id,vm.config);
        		/*var reportPagearea = vm.config.reportPagearea.split(',');
				var reportPrintarea = vm.config.reportPrintarea.split(',');
				var objstr = $("#table").html();
				console.log(objstr);
				LODOP = getLodop();	
				var md = -1;
				LODOP.PRINT_INIT('订单打印');
				if(md >= 0){
					LODOP.SET_PRINTER_INDEX(md);
				}
				console.log(reportPrintarea[0]);
				console.log(reportPrintarea[1]);
				LODOP.SET_PRINT_PAGESIZE(2,0,0,'报表');
				LODOP.ADD_PRINT_TABLE('5mm','5mm',"360mm",'220mm',document.getElementById("table").innerHTML);
				LODOP.PREVIEW();*/
        	},
        	getNormalReport:function(){
        		TX.msg('正在读取数据',{time:200000});
        		vm.normal_report_list = [];
        		vm.normal_report_sum = 0;
        		vm.normal_report_cs = 0;
        		vm.normal_search.timeArea = vm.config.timeAreareport;
        		$.post(logic_urls.getNormalReport,vm.normal_search,
        			function(data){
        				var json = TX.toJson(data);
        				console.log(json);
        				if(json.status == 1){
        					layer.closeAll();
        					vm.normal_report_list = json.data;
        					vm.normal_report_sum = json.sum;
        					vm.normal_report_cs = json.cs;
        					avalon.scan();
        				}else{
        					TX.msg(json.msg);
        				}
        			}

        		);
        	},
        	exportNormalReport:function(){
        		if(vm.normal_report_list.length <= 0){
        			TX.msg('没有可导出的内容',{time:3000});
        			return false;
        		}
        		var sk = '';
        		for(var k in vm.normal_search){
        			sk = sk + k + '=' + vm.normal_search[k] + '&';
        		}
        		sk = sk.substr(0,sk.length - 1);
        		console.log(sk);
        		window.open(logic_urls.exportNormalReport + '?' + sk);
        	},
        });
		vm.load();
	});
	</script>
</body>
</html>